from datetime import datetime

time='20181203'
a=datetime.strptime(time,'%Y%m%d') # datetime.datetime(2018,12,3,0,0)